sledge.users = {}
sledge.groups = {}

function sledge.LoadPerms(ply)
	users = sledge.StringToTable(file.Read("sledge/users.txt"))
	for k,v in pairs(users) do
		PrintTable(v)
		sledge.Debug("ID1: "..k)
		sledge.Debug("ID2: "..ply:SteamID())
		if(v.SteamID:lower() == ply:SteamID():lower()) then
			table.insert(sledge.users, v)
			sledge.Msg(ply, "[Sledge] Set access.")
		end
	end
end
hook.Add("PlayerInitialSpawn", "sledge_loadperms", sledge.LoadPerms)

function sledge.AddUser(user, group)
	if(!sledge.GroupExists(group)) then
		return false
	end
	users = sledge.StringToTable(file.Read("sledge/users.txt"))
	local exists = 0
	local user2 = {}
	local user2k = nil
	for k,v in pairs(users) do
		if(v.SteamID == user:SteamID()) then
			exists = 1
			user2 = v
		end
	end
	if(exists == 0) then
		user2.SteamID = user:SteamID()
		user2.Name = user:Nick()
		user2.groups = {}
		table.insert(user2.groups, group)
		users[user:SteamID()] = user2
	elseif(exists == 1) then
		table.insert(user2.groups, group)
		users[user:SteamID()] = user2
	end
	file.Write("sledge/users.txt", sledge.TableToString(users))
	return true
end

function sledge.GroupExists(group)
	return true
end

function sledge.RemoveUser(user, group)
	Msg("Remove user function called, coming later")
end

function sledge.AddGroup(group, permission)
	
end

function sledge.RemoveGroup(group, permission)
	Msg("Remove group function called, coming later")
end

function sledge.CheckPerms(user, permission)
	if(permission == "kick") then return true end
	return false
end
